package com.zzy;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.jobclient.JobClient;
import com.github.ltsopensource.jobclient.domain.Response;

@Controller
public class IndexAction implements InitializingBean{
	
    /**
     * 自己的业务类,就可以这样引用了
     */
    @Autowired
    private JobClient jobClient;
	
	@RequestMapping("/java")
	@ResponseBody
	public String hellojava() {
		  // 这里模拟提交任务

        Job job = new Job();
        job.setTaskId("11111111111");
   
        
      // shard项目       lts.tasktracker.dispatch-runner.shard-value=jobname   对应job shardvalue
        job.setParam("jobname", "111");
    
        job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
        job.setNeedFeedback(true);
        job.setReplaceOnExist(true);        // 当任务队列中存在这个任务的时候，是否替换更新
//        job.setCronExpression("0 0/1 * * * ?");
//        job.setTriggerTime(DateUtils.addDay(new Date(), 1));
        Response response = jobClient.submitJob(job);
        System.out.println(response);
		return response.toString();
	}
	
	
	
	@RequestMapping("/shard")
	@ResponseBody
	public String hello() {
		  // 这里模拟提交任务

        Job job = new Job();
        job.setTaskId("t_555");
        
        job.setParam("shardId", "A");
        job.setParam("jobname", "111");
        job.setParam("shopId", "1122222221");
    
        job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
        job.setNeedFeedback(true);
        job.setReplaceOnExist(true);        // 当任务队列中存在这个任务的时候，是否替换更新
//        job.setCronExpression("0 0/1 * * * ?");
//        job.setTriggerTime(DateUtils.addDay(new Date(), 1));
        Response response = jobClient.submitJob(job);
        System.out.println(response);
		return response.toString();
	}
	
	
	
	

	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		
	}

}
